package jhunter.rt;

import jhunter.rt.conf.AppsConfigLoader;
import jhunter.rt.conf.Node;
import jhunter.rt.conf.PathInfo;
import jhunter.rt.conf.ext.ActionExt;
import jhunter.web.mvc.controller.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DefaultJHunterContainer implements JHunterContainer {

	@Autowired
	private AppsConfigLoader appsConfigLoader;

	@Override
	public boolean hasMatchUri(PathInfo pathInfo) {
		return appsConfigLoader.getUriNodeMap().containsKey(pathInfo);
	}

	@Override
	public Controller getControllerInstance(PathInfo pathInfo) {
		Node action = appsConfigLoader.getUriNodeMap().get(pathInfo);
		ActionExt aext = (ActionExt) action.getObject();
		return aext.getGroovyController();
	}

	public AppsConfigLoader getAppsConfigLoader() {
		return appsConfigLoader;
	}

	public void setAppsConfigLoader(AppsConfigLoader appsConfigLoader) {
		this.appsConfigLoader = appsConfigLoader;
	}

}
